#include "client/websocket_client.h"
#include <iostream>
#include <string>
#include <thread>
#include <chrono>

int main() {
    websocket::WebSocketClient client("127.0.0.1", 8080);
    
    // 设置消息处理回调
    client.setMessageHandler([](const std::string& message) {
        std::cout << "服务器响应: " << message << std::endl;
    });
    
    // 连接服务器
    if (!client.connect()) {
        std::cerr << "连接服务器失败" << std::endl;
        return 1;
    }
    
    std::cout << "WebSocket客户端已启动，输入消息发送到服务器，输入'quit'退出" << std::endl;
    
    // 交互循环
    std::string input;
    while (client.isConnected()) {
        std::cout << "请输入消息: ";
        std::getline(std::cin, input);
        
        if (input == "quit") {
            break;
        }
        
        client.sendText(input);
        std::this_thread::sleep_for(std::chrono::milliseconds(100));
    }
    
    client.disconnect();
    std::cout << "客户端已断开连接" << std::endl;
    
    return 0;
}